package org.springblade.mach.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.common.constant.ResultConstant;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.flow.core.constant.ProcessConstant;
import org.springblade.mach.entity.DrawingAttachApproval;
import org.springblade.mach.service.IDrawingAttachApprovalService;
import org.springblade.modules.resource.entity.Attach;
import org.springblade.modules.resource.service.IAttachService;
import org.springblade.modules.resource.vo.AttachVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/drawing/attachapproval")
@Api(value = "图纸审批", tags = "审批接口")
public class DrawingAttachApprovalController extends BladeController{

	private IDrawingAttachApprovalService drawingAttachApprovalService;

	@PostMapping("/handleDrawingAttachApproval")
	public R handleDrawingAttachApproval(@RequestBody DrawingAttachApproval drawingAttachApproval) {
		if (drawingAttachApproval != null && drawingAttachApproval.getAttachId() != null) {
			return R.fail(ResultConstant.PARAM_EMTPY_ERROR);
		}
		boolean result = drawingAttachApprovalService.handleDrawingAttachApproval(drawingAttachApproval);
		return R.data(result);
	}

	/**
	 * 获取历史审批记录
	 * @param drawingUploadId
	 * @param taskDefinitionKey
	 * @return
	 */
	@ApiOperation(value = "获取历史审批记录", notes = "传入drawingUploadId" , position = 2)
	@GetMapping("/findHistoryApprovalList")
	public R findHistoryApprovalList(@RequestParam("drawingUploadId") Long drawingUploadId, @RequestParam("taskDefinitionKey") String taskDefinitionKey) {
		List<DrawingAttachApproval> attachApprovalList = drawingAttachApprovalService.findHistoryApprovalList(drawingUploadId, taskDefinitionKey);
		return R.data(attachApprovalList);
	}

	@ApiOperation(value = "复选同意审批", notes = "传入drawingAttachApprovalList" , position = 3)
	@PostMapping("/handleDrawingAttachApprovalByBatch")
	public R handleDrawingAttachApprovalByBatch(@RequestBody List<DrawingAttachApproval> drawingAttachApprovalList) {
		if (CollectionUtil.isEmpty(drawingAttachApprovalList)) {
			return R.fail(ResultConstant.PARAM_EMTPY_ERROR);
		}
		return drawingAttachApprovalService.approvalDrawingAttachApprovalByBatch(drawingAttachApprovalList);
	}
}
